# Harris 1969 Changing Morality Survey, study no. 1933

## packages 
library("Hmisc")
library("dplyr")

## set working directory to replication repository

## download data
survey <- sasxport.get("Harris_Data/Harris 1969 Changing Morality Survey, study no. 1933/harris_s1933_sas.export")

## pid
survey$pid <- c(1:nrow(survey))

## study number
survey$study <- as.character(1933)
str(survey$study)

## year
survey$year <- 1969
class(survey$year)

## geographpic data
survey$urban <- NA
class(survey$urban)

## region 
survey$region <- NA

## respondent head of house
survey$hh <- NA

## inequality increasing
summary(survey$q10a.1)
survey$inequality <- as.character(survey$q10a.1)
str(survey$inequality)

## inequality variable version
survey$inequality.variable <- 1
class(survey$inequality.variable)

## union 
survey$union.self <- NA
survey$union.other <- NA

## Are you employed? what kind of employment?
summary(survey$f2a)
survey$employed <- as.character(survey$f2a)
str(survey$employed)

## employed.self
survey$employed.self <- NA

## Occupation
summary(survey$f2b)
survey$occupation <- as.character(survey$f2b)
class(survey$occupation)

## occupation.self
survey$occupation.self <- NA

## household size
survey$hhsize <- NA

## Education
summary(survey$f3c)
survey$educ <- as.character(survey$f3c)
str(survey$educ)

## Income
summary(survey$f6)
survey$income <- as.character(survey$f6)
str(survey$income)

## Age 
## broken out by gender (f5c.1, f5c.2)
## for five respondents answered both
## and for one of those had different responses
sum(!is.na(survey$f5c.1) & !is.na(survey$f5c.2))
survey[!is.na(survey$f5c.1) & !is.na(survey$f5c.2), 
       c("s1", "f5c.1", "f5c.2")]

## respondent 1412 is male
## so we make the female age value NA for that 
## respondent
survey$f5c.2[1412] <- NA
survey$f5c.1[1412]
survey$age <- ifelse(is.na(survey$f5c.1), 
                     as.character(survey$f5c.2), 
                     as.character(survey$f5c.1))

survey$age <- as.character(survey$age)
str(survey$age)

## race
summary(survey$f7)
survey$race <- as.character(survey$f7)
table(survey$race)

## politics 
summary(survey$a1d)
survey$party <- as.character(survey$a1d)
str(survey$party)

## ideology
survey$ideology <- NA

## gender
summary(survey$s1)
survey$gender <- as.character(survey$s1)
str(survey$gender)

## religion
table(survey$f5a)
survey$religion <- as.character(survey$f5a)
class(survey$religion)

## factuals
survey$factual1 <- NA
survey$factual2 <- NA
survey$factual3 <- NA

## alienation index
survey$dontcare <- as.character(survey$q10a.2)
survey$dontcount <- as.character(survey$q10a.3)
survey$leftout <- as.character(survey$q10a.8)

## question_place

survey$question_place <- "before party"

### put together data set
survey_1933 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
                         "inequality", "inequality.variable", "union.self", "union.other",
                         "employed", "employed.self", "occupation", "occupation.self", "hhsize", "educ", "income", 
                         "age", "race", "party", "ideology", "gender", "religion",
                         "factual1", "factual2", "factual3", "dontcare", "dontcount", "leftout",
                         "question_place")]

## save dataset in folder 
#saveRDS(survey_1933, file = "Harris_Data/survey_1933.rds")



